package org.akomantoso.core.io.util;

import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 */
public final class DateUtil {

	private DateUtil(){}
	
	/**
	 *	Convert String date in format yyyy-mm-dd to a calendar.
	 */
	public static Calendar convert(String date) {
		return new GregorianCalendar(Integer.valueOf(date.substring(0,4)),
				 Integer.valueOf(date.substring(5,7))-1, 
				 Integer.valueOf(date.substring(8,10)));
	}

	/**
	 *	Convert String date in format yyyy-mm-ddThh:MM:ss to a calendar.
	 */
	public static Calendar convertTime(String time) {
		return new GregorianCalendar(Integer.valueOf(time.substring(0,4)),
				 Integer.valueOf(time.substring(5,7))-1, 
				 Integer.valueOf(time.substring(8,10)),
				 Integer.valueOf(time.substring(11,13)),
				 Integer.valueOf(time.substring(14,16)),
				 Integer.valueOf(time.substring(17,19))
				);
	}
	
}